package com.rbac.api.mybatis.mapper;


import com.rbac.api.mybatis.entityCus.CusAdRoleLinkedEntity;
import com.rbac.api.mybatis.entityCus.CusRoleHaveMenusMemberEntity;
import com.rbac.api.mybatis.sqlProvider.AdminRolesMenusSqlProvider;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

@Mapper
public interface AdminRolesMenusMapper {



    ///角色关联的菜单数据入库
    @InsertProvider(type=AdminRolesMenusSqlProvider.class, method="insertManyRolesMenusDataSelective")
    int insertManyRolesMenusDataSelective(@Param("list") List<CusAdRoleLinkedEntity> record);




    ///根据角色编号获取拥有的菜单成员
    @Select({
            "select\n",
            "arm.role_no,arm.menu_no,am.menu_name\n",
            "from admin_roles_menus as arm\n",
            "LEFT JOIN admin_menus as am on arm.menu_no=am.menu_no\n",
            "where arm.role_no = #{roleNo,jdbcType=VARCHAR}"
    })
    @Results({
            @Result(column="role_no", property="roleNo", jdbcType= JdbcType.VARCHAR),
            @Result(column="menu_no", property="menuNo", jdbcType= JdbcType.VARCHAR),
            @Result(column="menu_name", property="menuName", jdbcType=JdbcType.VARCHAR)
    })
    List<CusRoleHaveMenusMemberEntity> selectHaveMenusMemberByRoleNoMapper(@Param("roleNo") String roleNo);


    ///deleteDataByRoleNoMapper
    ///根据角色编号删除关联的菜单数据
    @Delete({
            "DELETE FROM `admin_roles_menus`\n",
            "where role_no = #{roleNo,jdbcType=VARCHAR}\n"
    })
    int deleteDataByRoleNoMapper(@Param("roleNo") String roleNo);






}